<template>
  <div class="header">
    <div class="collapse-btn" @click="collapseChange">
      <i class="el-icon-menu"></i>
    </div>
    <div class="logo">后台管理</div>
    <div class="header-right">
      <div class="btn-fullscreen" @click="handleFullScreen">
        <el-tooltip
          :content="fullscreen ? `取消全屏` : `全屏`"
          placement="bottom"
        >
          <i class="el-icon-rank"></i>
        </el-tooltip>
      </div>
      <div class="user-avator">
        <img src="../assets/img/1.jpg" />
      </div>
      <el-dropdown class="user-name" trigger="click" @command="hadleCommand">
        <span class="el-dropdown-link">
          {{ userName }}
          <i class="el-icon-caret-bottom"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="">清除本地数据</el-dropdown-item>
          <el-dropdown-item command=""><a @click="visibleEditPasswordDialog = true">修改登录密码</a></el-dropdown-item>
          <el-dropdown-item command=""><a @click="visibleEditInfoDialog = true">修改我的信息</a></el-dropdown-item>
          <el-dropdown-item command="logout">退出登录</el-dropdown-item>
          <!-- <el-button type="" @click="visibleEditPasswordDialog = true"></el-button> -->
        </el-dropdown-menu>
      </el-dropdown>
    </div>

    <el-dialog
      title="修改密码"
      :visible.sync="visibleEditPasswordDialog"
      width="30%"
      >
      <el-form ref="passForm" :model="passForm" :rules="passFormRules" label-width="80px">
        <el-form-item label="新密码" prop="password">
          <el-input v-model="passForm.password"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visibleEditPasswordDialog = false">取 消</el-button>
        <el-button type="primary" @click="visibleEditPasswordDialog = false">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="修改用户信息"
      :visible.sync="visibleEditInfoDialog"
      width="30%"
      >
      <el-form ref="infoForm" :model="infoForm" :rules="infoFormRules" label-width="80px">
        <el-form-item label="用户昵称" prop="nikeName">
          <el-input v-model="infoForm.nikeName"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visibleEditInfoDialog = false">取 消</el-button>
        <el-button type="primary" @click="visibleEditInfoDialog = false">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import bus from "../assets/js/bus";
export default {
  data() {
    return {
      collapse: false,
      fullscreen: false,
      visibleEditPasswordDialog:false,
      visibleEditInfoDialog:false,
      passForm:{
        password:''
      },
      infoForm:{
        nikeName:''
      },
      passFormRules:{
        password:[
          {required: true, message: '请输入新密码', trigger: 'blur'}
        ]
      },
      infoFormRules:{
        nikeName:[
          {required: true, message: '请输入用户昵称', trigger: 'blur'}
        ]
      }
    };
  },
  computed: {
    userName() {
      return localStorage.getItem("userName");
    },
  },
  methods: {
    //侧边栏
    collapseChange() {
      this.collapse = !this.collapse;
      bus.$emit("collapse", this.collapse);
    },
    //全屏事件
    handleFullScreen() {
      if (this.fullscreen) {
        if (document.exitFullscreen) {
          document.exitFullscreen();
        } else if (document.webkitCancelFullScreen) {
          //chrome safari
          document.webkitCancelFullScreen();
        } else if (document.mozCancelFullScreen) {
          //firefox
          document.mozCancelFullScreen();
        } else if (document.msExitFullScreen) {
          //ie
          document.msExitFullScreen();
        }
      } else {
        let element = document.documentElement;
        if (element.requestFullscreen) {
          element.requestFullscreen();
        } else if (element.webkitRequestFullScreen) {
          //chrome safari
          element.webkitRequestFullScreen();
        } else if (element.mozRequestFullScreen) {
          //firefox
          element.mozRequestFullScreen();
        } else if (element.msRequestFullScreen) {
          //ie
          element.msRequestFullScreen();
        }
      }
      this.fullscreen = !this.fullscreen;
    },
    hadleCommand(command) {
      if (command == "logout") {
        localStorage.removeItem("userName");
        this.$router.push("/");
      }
    },
  },
};
</script>



<style scoped>
.header {
  position: relative;
  background-color: #253041;
  box-sizing: border-box;
  width: 100%;
  top: 0;
  left: 0;
  height: 70px;
  font-size: 22px;
  color: #ffffff;
}
.collapse-btn {
  float: left;
  padding: 0 21px;
  cursor: pointer;
  line-height: 70px;
}
.header .logo {
  float: left;
  line-height: 70px;
}
.header-right {
  float: right;
  padding-right: 50px;
  display: flex;
  height: 70px;
  align-items: center;
}
.btn-fullscreen {
  transform: rotate(45deg);
  margin-right: 5px;
  font-size: 24px;
}
.user-avator {
  margin-left: 20px;
}

.user-avator img {
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}
.user-name {
  margin-left: 10px;
}
.el-dropdown-link {
  color: #ffffff;
  cursor: pointer;
}
</style>